#ifndef __VIDEO_PARSER_H__
#define __VIDEO_PARSER_H__
extern "C"
{
    #include <libavutil/imgutils.h>
    #include <libavutil/samplefmt.h>
    #include <libavutil/timestamp.h>
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#define INBUF_SIZE 4096

typedef void (*frame_callback)(unsigned char *buf, int wrap, int xsize, int ysize);


class VideoParser
{
private:
    std::ifstream video_file;
    std::string filename;
    frame_callback callback = nullptr;
    const AVCodec *codec = nullptr;
    AVCodecParserContext *parser = nullptr;
    AVCodecContext *c = nullptr;
    AVFrame *frame;
    AVFormatContext *fmt_ctx = nullptr;
    uint8_t *inbuf;
    uint8_t *data;
    uint32_t   data_size;
    int ret;
    int eof;
    AVPacket *pkt;

    int open_codec_context(int *stream_idx,
                              AVCodecContext **dec_ctx, AVFormatContext *fmt_ctx, enum AVMediaType type);

    char *buf; //用于decode
    void demuxing();
    void read_file();
    void process();
public:
    VideoParser(std::string file_name);
    ~VideoParser();
    void setCallBack(frame_callback callback);
    void decode();
};

#endif